//
//  ViewController.m
//  test
//
//  Created by Ruin on 2020/7/28.
//  Copyright © 2020年 Ruin. All rights reserved.
//

#define kScreenBounds [[UIScreen mainScreen] bounds]
#define kScreenWidth kScreenBounds.size.width
#define kScreenHeight kScreenBounds.size.height
// 判断是否是iPhone X
#define iPhoneX ((int)(floor((kScreenHeight / kScreenWidth) * 100)) == 216 ? YES : NO)
// 状态栏高度
#define StateBarHeight (iPhoneX ? 44.f : 20.f)
// 导航栏高度
#define NavBarHeight (iPhoneX ? 88.f : 64.f)
// tabBar高度
#define TabbarHeight (iPhoneX ? (49.f + 34.f) : 49.f)
// home indicator
#define HOME_INDICATOR_HEIGHT (iPhoneX ? 34.f : 0.f)


#import "ViewController.h"
//#import "testViewController.h"
#import "JQHomeItemVC.h"
#import "JQHomeOtherItemVC.h"

@interface ViewController ()

@end

@implementation ViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addHeaderBG];
    [self setUpWMPageC];
    
//    [self groupNotify];
    
}

- (void)setUpWMPageC{
    self.titles = @[@"全部",@"付款",@"发货",@"收货"];
    self.titleSizeSelected = 16.0f;
    self.titleSizeNormal = 15.0f;
    NSMutableArray *array = [[NSMutableArray alloc] init];
    for (NSString *object in self.titles) {
        CGFloat width = [object boundingRectWithSize:CGSizeMake(MAXFLOAT, 20.0f) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width + 16.0f;
        NSNumber *number = [[NSNumber alloc]initWithFloat:width];
        [array addObject:number];
    }
    self.itemsWidths = array;
    self.titleColorSelected = [UIColor redColor];
    self.titleColorNormal = [UIColor whiteColor];
    [self reloadData];
}

- (void)addHeaderBG {
    UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 125)];
    bg.backgroundColor = [UIColor blueColor];
    [self.view addSubview:bg];
    
    UIImageView *topImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 125)];
    [self.view addSubview:topImageV];
    topImageV.image = [UIImage imageNamed:@"6410"];
    
}


#pragma mark - WMPageControllerDataSource

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titles.count;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, HOME_INDICATOR_HEIGHT + 13, kScreenWidth, 30);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    contentView.backgroundColor = [UIColor clearColor];
    return CGRectMake(0, 43 + HOME_INDICATOR_HEIGHT, kScreenWidth, kScreenHeight - 43 - HOME_INDICATOR_HEIGHT - NavBarHeight);
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    if (index == 0) {
        JQHomeItemVC *itemVC = [[JQHomeItemVC alloc] init];
        return itemVC;
    }else{
        JQHomeOtherItemVC *itemVC = [[JQHomeOtherItemVC alloc] init];
        itemVC.roomTagId = @"1";
        return itemVC;
    }
//    JQHomeItemVC *vc = [[JQHomeItemVC alloc] init];
//    return vc;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    
    return self.titles[index];
}

/**
 * 队列组 dispatch_group_notify
 */
- (void)groupNotify {
    NSLog(@"currentThread---%@",[NSThread currentThread]);  // 打印当前线程
    NSLog(@"group---begin");
    
    dispatch_group_t group =  dispatch_group_create();
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 追加任务 1
        NSLog(@"currentThread 1---%@",[NSThread currentThread]);      // 打印当前线程
    });
    
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 追加任务 2
        NSLog(@"currentThread 2---%@",[NSThread currentThread]);      // 打印当前线程
    });
    
    dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_group_async(group, dispatch_get_main_queue(), ^{
            // 等前面的异步任务 1、任务 2 都执行完毕后，回到主线程执行下边任务
            NSLog(@"currentThread 3---%@",[NSThread currentThread]);      // 打印当前线程
            
            
            NSLog(@"group---end");
        });
    });
}

@end
